/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Objet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author zouafr
 */
@WebServlet(name = "Controller", urlPatterns = {"/Controller"})
public class Controller extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       /* response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
                
        
         if(request.getParameter("do")!=null){
             
                if(request.getParameter("do").equalsIgnoreCase("ajouter")){       
                    boolean ok=true;
                    String titre=(String)request.getParameter("titre");
                    float prix;
                 
                    try {
                        System.out.println("Dans la création des variables");
                        prix= Float.valueOf((String)request.getParameter("prix")); 
                        System.out.println(prix);
                    }
                    catch (NumberFormatException nfe) {
                    //c'est pas un nombre
                        prix=0;
                        ok=false;                                
                    }
                    
                    if(!ok){
                        // problème de données on a pas pu insérer 
                        request.setAttribute("insertion",0);
                    }else{
                        // enregistrement dans la base possible 
                        System.out.println("On s'apprete a inserer");
                        BDInsert queryAjout=new BDInsert(titre, prix);
                        request.setAttribute("insertion",1);
                        System.out.println("insersion réussi");
                    }
                }
        }         
        
        
        BD connexionBD = new BD();
        
        System.out.println(connexionBD.getArrList());
               
        
        RequestDispatcher rd=null;
        request.setAttribute("arrList",connexionBD);
        
        rd=request.getRequestDispatcher("AfficheDVD.jsp");    
        rd.forward(request, response);
        
        System.out.println("réussi");*/
               
 
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
